Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
emailjs-mime-codec
Advanced tools
emailjs-mime-codec
allows you to encode and decode between different MIME related encodings. Quoted-Printable, Base64 etc.
All input can use any charset (in this case, the value must not be a string but an arraybuffer of Uint8Array) but output is always unicode.
npm install --save emailjs-mime-codec
import {
encode, decode, convert
mimeEncode, mimeDecode,
base64Encode, base64Decode,
quotedPrintableEncode, quotedPrintableDecode,
mimeWordEncode, mimeWordDecode,
mimeWordsEncode, mimeWordsDecode,
headerLineEncode, headerLinesDecode,
continuationEncode,
foldLines,
parseHeaderValue
} from 'emailjs-mime-codec'
encode(data: String) -> Uint8Array
decode(data: Uint8Array, charset: String) -> String
convert(data, charset: String) -> String
encode
takes a String and returns a UTF-8 encoded Uint8Array.
decode
takes a Uint8Array along with a charset and decodes the typed array to a String. Charset defaults to UTF-8.
convert
chains encode and decode and converts an input string with a given encoding to a UTF-8 encoded Uint8Array.
Folds a long line according to the RFC 5322 http://tools.ietf.org/html/rfc5322#section-2.1.1
foldLines(str [, lineLengthMax[, afterSpace]]) -> String
For example:
foldLines('Content-Type: multipart/alternative; boundary="----zzzz----"')
results in
Content-Type: multipart/alternative;
boundary="----zzzz----"
Encodes a string into mime encoded word format http://en.wikipedia.org/wiki/MIME#Encoded-Word (see also mimeWordDecode
)
mimeWordEncode(str [, mimeWordEncoding[, fromCharset]]) -> String
For example:
mimeWordEncode('See on õhin test', 'Q');
Becomes with UTF-8 and Quoted-printable encoding
=?UTF-8?Q?See_on_=C3=B5hin_test?=
Decodes a string from mime encoded word format (see also mimeWordEncode
)
mimeWordDecode(str) -> String
For example
mimeWordDecode('=?UTF-8?Q?See_on_=C3=B5hin_test?=');
will become
See on õhin test
Encodes and splits a header param value according to RFC2231 Parameter Value Continuations.
continuationEncode(key, str [, fromCharset]) -> Array
filename
)str
is a typed array, use this charset to decode the value to unicode before encodingThe method returns an array of encoded parts with the following structure: [{key:'...', value: '...'}]
continuationEncode('filename', 'filename õäöü.txt', 20);
->
[ { key: 'filename*0*', value: 'utf-8\'\'filename%20' },
{ key: 'filename*1*', value: '%C3%B5%C3%A4%C3%B6' },
{ key: 'filename*2*', value: '%C3%BC.txt' } ]
This can be combined into a properly formatted header:
Content-disposition: attachment; filename*0*="utf-8''filename%20"
filename*1*="%C3%B5%C3%A4%C3%B6"; filename*2*="%C3%BC.txt"
Encodes a string into Quoted-printable format (see also quotedPrintableDecode
). Maximum line
length for the generated string is 76 + 2 bytes.
quotedPrintableEncode(str [, fromCharset]) -> String
Decodes a string from Quoted-printable format (see also quotedPrintableEncode
).
quotedPrintableDecode(str [, fromCharset]) -> String
Encodes a string into Base64 format (see also base64Decode
). Maximum line
length for the generated string is 76 + 2 bytes.
base64Encode(str [, fromCharset]) -> String
Decodes a string from Base64 format (see also base64Encode
) to an unencoded unicode string.
base64Decode(str [, fromCharset]) -> String
Encodes a string to a mime word.
mimeWordEncode(str[, mimeWordEncoding[, fromCharset]]) -> String
Encodes non ascii sequences in a string to mime words.
mimeWordsEncode(str[, mimeWordEncoding[, fromCharset]]) -> String
Decodes a complete mime word encoded string
mimeWordDecode(str) -> String
Decodes a string that might include one or several mime words. If no mime words are found from the string, the original string is returned
mimeWordsDecode(str) -> String
Encodes and folds a header line for a MIME message header. Shorthand for mimeWordsEncode
+ foldLines
.
headerLineEncode(key, value[, fromCharset])
value
parameter is a typed array, use this charset to decode the value to unicode before encodingParses a block of header lines. Does not decode mime words as every header might have its own rules (eg. formatted email addresses and such).
Return value is an object of headers, where header keys are object keys. NB! Several values with the same key make up an array of values for the same key.
headerLinesDecode(headers) -> Object
Parses a header value with key=value
arguments into a structured object. Useful when dealing with
content-type
and such.
parseHeaderValue(valueString) -> Object
Example
parseHeaderValue('content-type: text/plain; CHARSET="UTF-8"');
Outputs
{
"value": "text/plain",
"params": {
"charset": "UTF-8"
}
}
The MIT License
Copyright (c) 2013 Andris Reinman
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.```
FAQs
Encode and decode quoted printable and base64 strings
The npm package emailjs-mime-codec receives a total of 12,211 weekly downloads. As such, emailjs-mime-codec popularity was classified as popular.
We found that emailjs-mime-codec demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.